<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
	template="/WEB-INF/templates/default.xhtml">
	<ui:define name="content">
	
	<h1>Servicebook Web</h1>
	<div>
		<h3>Client registration</h3>
	</div>
	<h2>Search</h2>
	<h:form>
			<h:inputText id="name" value="#{personSearch.personName}" />
			<h:commandButton id="register" action="#{personSearch.findPerson}" value="Find" />
	</h:form>
	<h3>Person without account</h3>
		<h:form>
			<h:panelGroup rendered="#{empty searchResults}">
				<em>No results.</em>
			</h:panelGroup>
			<h:dataTable var="_client" value="#{searchResults}" rendered="#{not empty searchResults}" styleClass="simpletablestyle">
				<h:column>
					<f:facet name="header">Id</f:facet>
                #{_client.personId}
            </h:column>

				<h:column>
					<f:facet name="header">Name</f:facet>
                #{_client.personName}
            </h:column>
				<h:column>
					<f:facet name="header">Address</f:facet>
                #{_client.address}
            </h:column>
				<h:column>
					<f:facet name="header">Phone #</f:facet>
                #{_client.phone}
            </h:column>
				<h:column>
					<f:facet name="header">action</f:facet>
					<h:commandButton id="editPerson" action="#{clientController.initPerson(_client)}" value="Edit" />
					<h:commandButton id="createUser" value="create user" action="#{userController.createNewUser(_client)}">
					</h:commandButton>
					<h:commandButton id="addVehicle" action="#{vehicleController.createVehicle(_client)}" value="add vehicle" />
				</h:column>
			</h:dataTable>
		</h:form>
		<h3>Person with user account</h3>
		<h:form>
			<h:panelGroup rendered="#{empty searchResultUsers}">
				<em>No results.</em>
			</h:panelGroup>
			<h:dataTable var="_client" value="#{searchResultUsers}" rendered="#{not empty searchResultUsers}" styleClass="simpletablestyle">
				<h:column>
					<f:facet name="header">Id</f:facet>
                #{_client.personId}
            </h:column>

				<h:column>
					<f:facet name="header">Name</f:facet>
                #{_client.personName}
            </h:column>
				<h:column>
					<f:facet name="header">Address</f:facet>
                #{_client.address}
            </h:column>
				<h:column>
					<f:facet name="header">Phone #</f:facet>
                #{_client.phone}
            </h:column>
				<h:column>
					<f:facet name="header">action</f:facet>
					<h:commandButton id="editPerson" action="#{clientController.initPerson(_client)}" value="Edit" />
					<h:commandButton id="addVehicle" action="#{vehicleController.createVehicle(_client)}" value="add vehicle" />
				</h:column>
			</h:dataTable>
		</h:form>
		
		<h:form id="reg">
			<h2>Client Data</h2>
			<h:panelGrid columns="3" columnClasses="titleCell" style="white-space: nowrap;">
				<h:outputLabel for="name" value="Name:" />
				<h:inputText id="name" value="#{newPerson.personName}" />
				<h:message for="name" errorClass="invalid" />

				<h:outputLabel for="address" value="Address:" />
				<h:inputText id="address" value="#{newPerson.address}" />
				<h:message for="address" errorClass="invalid" />

				<h:outputLabel for="phoneNumber" value="Phone #:" />
				<h:inputText id="phoneNumber" value="#{newPerson.phone}" />
				<h:message for="phoneNumber" errorClass="invalid" />
			</h:panelGrid>

			<p>
				<h:panelGrid columns="2">
					<h:commandButton id="register" action="#{clientController.register}" value="Register" styleClass="register" rendered="#{clientController.newPerson.personName == null}" />
					<h:commandButton id="editPerson" action="#{clientController.editPerson}" value="Save changes" rendered="#{clientController.newPerson.personName != null}" />
					<h:commandButton id="cancelPerson" action="#{clientController.cancelPerson}" value="Cancel" />
					<h:messages styleClass="messages" errorClass="invalid" infoClass="valid" warnClass="warning" globalOnly="true" />
					<br />
				</h:panelGrid>
			</p>
		</h:form>
			<h:form>
			<h:commandLink action="#{login.logout()}" value="Logout" />
			</h:form>
	</ui:define>
</ui:composition>	